package com.it.web;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.it.entity.report.AiClaimReport;
import com.it.service.AiClaimReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import utils.R;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * <p>
 * 农户报案表（灾祸发生后报案记录） 前端控制器
 * </p>
 *
 * @author sunwz
 * @since 2025年09月19日
 */
@RestController
@RequestMapping("/aiClaimReport")
public class AiClaimReportController {
    @Autowired
    private AiClaimReportService aiClaimReportService;

    @PostMapping("/addReport")
    public R addReport(@RequestBody AiClaimReport aiClaimReport) {
        return aiClaimReportService.addReport(aiClaimReport);
    }
    @GetMapping("/all")
    public R selectReport(@RequestParam(value = "pageNum",required = false,defaultValue = "1") int pageNum,
                          @RequestParam(value = "pageSize",required = false,defaultValue = "5")int pageSize,
                          @RequestParam(value = "policyId",required = false)String policyId,
                          @RequestParam(value = "reportStatus",required = false)Integer reportStatus){
        return aiClaimReportService.selectPage(pageNum,pageSize,policyId,reportStatus);
    }

    @GetMapping("/{reportNo}")
    public R selectReportById(@PathVariable String reportNo){
        return aiClaimReportService.selectById(reportNo);
    }

    @GetMapping("/checkDuplicate")
    public R selectReportByPolicyIdAndTime(@RequestParam(value = "policyId",required = false) String policyId,
                                           @RequestParam(value = "reportTime",required = false) LocalDateTime reportTime){
        return aiClaimReportService.selectByPolicyIdAndTime(policyId,reportTime);
    }

    @PutMapping("/updateStatus")
    public R updateStatus(@RequestParam String reportNo,@RequestParam Integer reportStatus){
        return aiClaimReportService.update(reportNo,reportStatus);
    }

    // 查勘调度表相关，查询待查勘任务
    @GetMapping("/dispatch")
    public R selectDispatch(@RequestParam(defaultValue = "1",value = "pageNum",required = false) Integer pageNum,
                            @RequestParam(defaultValue = "5",value = "pageSize",required = false) Integer pageSize) {
        return aiClaimReportService.selectDispatch(pageNum,pageSize);
    }


    /**
     * 调度表相关，更新报案表状态
     */
    @PutMapping("/update")
    public R update(@RequestParam(value = "reportNo") String reportNo,
                    @RequestParam(value = "reportStatus") Integer reportStatus,
                    @RequestParam(value = "workOutStatus",required = false) Integer workOutStatus) {
        return aiClaimReportService.dispatchUpdate(reportNo, reportStatus, workOutStatus);
    }

    @GetMapping("/selectOne")
    public AiClaimReport selectOne(@RequestParam(value = "reportNo") String reportNo){

        return aiClaimReportService.getOne(reportNo);
    }

    @PostMapping("/add")
    public AiClaimReport add(@RequestBody AiClaimReport aiClaimReport,
                             @RequestParam BigDecimal lossEstimate){
        return aiClaimReportService.add(aiClaimReport,lossEstimate);

    }

}
